import axios from 'axios';
import {message} from 'antd';

axios.interceptors.request.use(config => {
  let tempConfig = {...config};
  console.log(tempConfig);
  return tempConfig;
}, error => {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(response => {
  // 对响应数据做点什么
  const msg = response.data.msg;
  if (msg) {
    const ShowMsg = !(
      msg.includes('查询')
      || msg.includes('查看')
      || msg.includes('获取')
      || msg.includes('接收')
      || msg.includes('返回')
      || msg.includes('用户未查看任务数')
      || msg.includes('访问城市')
      || msg.includes('ok')
    );
    switch (response.data.code) {
      case 100:
        ShowMsg && message.success(msg);
        break;
      // case 206:
      //   localStorage.clear();
      //   window._router.replace("/login");
      //   break;
      default:
        return message.error(msg);
    }
    return response.data;
  } else {
    return response;
  }
}, error => {
  // 对响应错误做点什么
  return Promise.reject(error);
});

export default axios;
